package com.alibaba.algo.apiimpl.user;

import com.alibaba.algo.cooperation.common.BaseResult;
import com.alibaba.algo.cooperation.usercomponent.service.user.SysSyncLogService;
import com.alibaba.algo.cooperation.usercomponent.vo.req.user.SysSyncLogRequestVO;
import com.alibaba.algo.domain.user.SysSyncLogDomain;
import com.alibaba.algo.entity.user.SysSyncLog;
import com.alibaba.algo.util.DateConverterUtils;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.ObjectUtils;
import org.springframework.web.bind.annotation.RestController;


@Slf4j
@RestController
public class SysSyncLogServiceImpl implements SysSyncLogService {

    @Autowired
    private SysSyncLogDomain sysSyncLogDomain;

    @Override
    @Transactional(propagation = Propagation.REQUIRED, rollbackFor = Exception.class)
    public BaseResult insert(SysSyncLogRequestVO sysSyncLogRequestVO) {
        SysSyncLog sysSyncLog = new SysSyncLog();
        BeanUtils.copyProperties(sysSyncLogRequestVO, sysSyncLog);
        sysSyncLog.setSuccessCount(ObjectUtils.isEmpty(sysSyncLogRequestVO.getSuccessDataCount()) ? null : sysSyncLogRequestVO.getSuccessDataCount());
        sysSyncLog.setFailureCount(ObjectUtils.isEmpty(sysSyncLogRequestVO.getFailureDataCount()) ? null : sysSyncLogRequestVO.getFailureDataCount());
        sysSyncLog.setOptTime(DateConverterUtils.asLocalDateTime(sysSyncLogRequestVO.getOptTime()));
        sysSyncLogDomain.insert(sysSyncLog);
        return BaseResult.buildSuccess(sysSyncLog.getId());
    }

    @Override
    public BaseResult delete(SysSyncLogRequestVO sysSyncLogRequestVO) {
        return null;
    }

    @Override
    public BaseResult update(SysSyncLogRequestVO sysSyncLogRequestVO) {
        return null;
    }
}
